package com.wedimob.bo;

import nf.fr.eraasoft.pool.ObjectPool;

import com.google.gson.Gson;
import com.wedimob.pool.PoolManager;

public abstract class SerializableBO<T> {

	public static <T> T fromString(String json, Class<T> cl) {
		ObjectPool<Gson> objectPool = PoolManager.get(Gson.class);
		Gson gson = null;
		try {
			gson = objectPool.getObj();
			return (T) gson.fromJson(json, cl);
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			objectPool.returnObj(gson);
		}
	}

	@Override
	public String toString() {
		ObjectPool<Gson> objectPool = PoolManager.get(Gson.class);
		Gson gson = null;
		try {
			gson = objectPool.getObj();
			return gson.toJson(this);
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			objectPool.returnObj(gson);
		}
	}
}
